home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / playin_1 / gfxandar.bas next >
BASIC Source File  |  1999-08-17  |  4KB  |  90 lines

  1. Attribute VB_Name = "GFXandArrays"
  2. ' Graphics functions and constants used in the example.
  3. Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  4. Public Const SRCAND = &H8800C6    ' Masks
  5. Public Const SRCPAINT = &HEE0086  ' onto masks
  6. Public Const SRCCOPY = &HCC0020   ' backgrounds
  7.  
  8. '*****************************************************
  9. Public Const Computer = 1
  10. Public Const Human = 2
  11. Public Const ConstBatSpeed = 7
  12. Public Const Tilesize = 32
  13.  
  14. Private Type PlayfieldData
  15.    DivideByX As Integer   ' the amount of times you can divide the Playfield.Width by 32
  16.    DivideByY As Integer   ' the amount of times you can divide the Playfield.Height by 32
  17. End Type
  18.  
  19. Private Type BallData
  20.   SpeedX As Integer           ' to hold Speed
  21.   SpeedY As Integer           ' to hold + & - Values for direction & Position
  22.   PositionX As Integer        ' to hold + & - Values for Position
  23.   PositionY As Integer        ' to hold + & - Values for Position
  24.   Height As Integer           ' height offset for ball shadow
  25.   GoingUpOrDown As Boolean    ' to hold + & - Values for direction  True=down
  26.   GoingLeftOrRight As Boolean ' to hold + & - Values for direction  True=Left
  27.   MinSpeedX As Integer        'minimum X speed the ball can travel
  28.   MinSpeedY As Integer        'minimum Y speed the ball can travel
  29. End Type
  30.  
  31. Private Type BatData
  32.   Speed As Integer           ' can not be more than 10 pixels per move
  33.   PositionX As Integer    ' to hold + & - Values for Position
  34.   PositionY As Integer    ' to hold + & - Values for Position 5 below top and 5 above bottom of playfield
  35. End Type
  36.  
  37. Private Type PlayerData
  38.   Name As String          'hold player name
  39.   Score As Long           'hold score
  40. End Type
  41.  
  42. Public Ball As BallData             ' use like  Ball.SpeedX
  43. Public Bat(1 To 2) As BatData       ' use like  Bat(2).PositionY
  44. Public player(1 To 2) As PlayerData ' use like  Player(1).Name
  45. Public Map As PlayfieldData         ' use like  Map.DivideByY
  46.  
  47. Public Sub SetUPData()
  48.  
  49.   player(Computer).Name = "Computer"
  50.   player(Human).Name = "Human"
  51.   player(Computer).Score = 0
  52.   player(Human).Score = 0
  53.   Bat(Computer).PositionY = 2
  54.   Bat(Human).PositionY = 10
  55.   Bat(Computer).Speed = ConstBatSpeed 'Computer
  56.   Bat(Human).Speed = 0 'Human do not set until key down, see form keydown event
  57.   Ball.Height = 5 ' height offset for ball shadow
  58.   Ball.GoingLeftOrRight = True
  59.   HitBatSpeedChangeDown
  60.   Ball.MinSpeedX = 8
  61.   Ball.MinSpeedY = 5
  62. End Sub
  63.  
  64. Private Sub GetARandomBallXDirection()
  65.   Do 'get a random value to take you left or right
  66.     Randomize
  67.     Ball.SpeedX = (30 * Rnd) - 15
  68.   Loop Until Ball.SpeedX > Ball.MinSpeedX Or Ball.SpeedX < -(Ball.MinSpeedX)
  69. End Sub
  70. Public Sub HitBatSpeedChangeDown()
  71.   GetARandomBallXDirection 'goto sub
  72.   
  73.   Randomize 'Get a positiveY direction Value
  74.   Ball.SpeedY = ((6 * Rnd) + 1) + Ball.MinSpeedY
  75. End Sub
  76. Public Sub HitBatSpeedChangeUp()
  77.   GetARandomBallXDirection 'goto sub
  78.   
  79.   Randomize 'Get a negative direction Value
  80.   Ball.SpeedY = -(((6 * Rnd) + 1) + Ball.MinSpeedY)
  81. End Sub
  82. Public Sub HitWallLeft()
  83.   'change from a negative value direction to a positive direction using this calculation
  84.   Ball.SpeedX = Ball.SpeedX + (-(Ball.SpeedX * 2))
  85. End Sub
  86. Public Sub HitWallRight()
  87.   'change from a positive value direction to a negative direction using this calculation
  88.   Ball.SpeedX = (Ball.SpeedX - ((Ball.SpeedX * 2) - 2))
  89. End Sub
  90.